package org.jeecg.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.domain.User;
import org.jeecg.result.ResultTool;
import org.jeecg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/changePassword",method = RequestMethod.POST)
    public ResultTool changePassword(@RequestBody User user){
        String username = user.getUsername();
        if (username == null){
            return new ResultTool(400,"用户名不能为空");
        }
        User user1 = userService.queryByUsername(username);
        if (user1 == null){
            return new ResultTool(400,"用户名错误");
        }
        Boolean result = userService.updatePasswordByUsername(username, user.getPassword());
        if (result){
            return new ResultTool(200,"修改成功");
        }else {
            return new ResultTool(400,"修改失败");
        }
    }

    @RequestMapping(value = "/resetNickNameAndPhoto")
    public ResultTool changeNicknameAndPhoto(@RequestBody User user){
        Boolean result = userService.updateUser(user);
        if (result){
            return new ResultTool(200,"修改成功");
        }
        return new ResultTool(400,"修改失败");
    }
































}
